<template>
	<view class="add">
		<view class="dheader">
			<view class="shop">
				<image :src="shop_info.category_image" mode="aspectFill" class="Boutique"></image>
				<view class="title">
					{{shop_info.shop_name}}
				</view>
				<view class="right" @click="toggle">
					<view class="size">
						切换
					</view>
					<image :src="$IMG_URL('/static/home/indicate.png')" mode="aspectFill" class="icon"></image>
				</view>
			</view>
		</view>
		<view class="card">
			<view class="row_box mb">
				<view class="left">
					<view class="required">
						*
					</view>
					<view class="size">
						使用类型
					</view>
				</view>
				<view class="right_box">
					<view v-for="(item,index) in typeList" :key="index" class="type"
						@click="changeTypeIndex(item,index)">
						<image
							:src="typeIndex == index ? $IMG_URL('/static/member/agreement2.png'):$IMG_URL('/static/member/agreement1.png')"
							mode="" class="icont"></image>
						<view class="size">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<view class="comlum_Y">
				<view class="row_box mb" v-if="typeIndex">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							节数门槛
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写节数门槛"
							v-model="query.lessons"  :clearable="false"/>
						<view class="unit">
							节
						</view>
					</view>
				</view>
				<view class="row_box mb">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							满减门槛
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写满减门槛"
							v-model="query.threshold"  :clearable="false"/>
						<view class="unit">
							元
						</view>
					</view>
				</view>
				<view class="row_box mb">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							面额
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写面额"
							v-model="query.face"  :clearable="false"/>
						<view class="unit">
							元
						</view>
					</view>
				</view>
				<view class="row_box mb">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							优惠券数量
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写优惠券数量"
							v-model="query.quantity"  :clearable="false"/>
						<view class="unit">
							张
						</view>
					</view>
				</view>
				<view class="row_box mb">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							领取后有效天数
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写领取后有效天数"
							v-model="query.days"  :clearable="false"/>
						<view class="unit">
							天
						</view>
					</view>
				</view>
				<view class="row_box ">
					<view class="left">
						<view class="required">
							*
						</view>
						<view class="size">
							每人限领数量
						</view>
					</view>
					<view class="right_box">
						<u-input type="number" :border="false" input-align="right" placeholder="请填写每人限领数量"
							v-model="query.rest"  :clearable="false"/>
						<view class="unit">
							张
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="addfoot">
			<view class="addbtn" @click.stop="getstoreCouponCreate">
				确认添加
			</view>
		</view>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import {
		atShop,
		storeCouponCreate
	} from '@/api/manager.js'
	export default {
		components: {
			FieldPopupVue,
		},
		data() {
			return {
				shop_info: {},
				query: {
					form: 'card',
					threshold: null,
					face: null,
					quantity: null,
					rest: null,
					days: null,
					lessons: null
				},
				shopName: '温州中庚漫游天地店',
				// 切换门店
				popupShow: false,
				Field: [],
				FieldIndex: -1,
				typeList: [
					'VIP会员',
					'私教课'
				],
				typeIndex: 0
			}
		},
		onLoad() {
			this.getatShop()
		},
		methods: {	
			getstoreCouponCreate() {
				storeCouponCreate(this.query).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'success',
							icon: false,
						})
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
							icon: false,
						})
					}
				})
			},
			changeTypeIndex(item, index) {
				this.typeIndex = index
				if (!index) {
					this.query.form = 'card'
				} else {
					this.query.form = 'course'
				}
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shop_info = res.data
					}
				})
			},
			// 切换门店
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.getatShop({
					shop_id: item.shop_id
				})
			},
			sure() {
				this.popupShow = false
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.add {
		display: flex;
		flex-direction: column;
		align-items: center;

		.dheader {
			width: 750rpx;
			height: 88rpx;
			background: #ffffff;
			padding: 26rpx 34rpx 0;
			margin-bottom: 24rpx;

			.shop {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 22rpx;

				.Boutique {
					width: 114rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}

				.title {
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
				}

				.right {
					display: flex;
					flex-direction: row;
					align-items: center;

					.size {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						color: #666666;
						margin-right: 8rpx;
					}

					.icon {
						width: 10rpx;
						height: 16rpx;
					}
				}
			}
		}

		.card {
			width: 702rpx;
			background: #ffffff;
			border-radius: 16rpx;
			padding: 40rpx;

			.mb {
				margin-bottom: 48rpx;
			}

			.comlum_Y {
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.row_box {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;

				.left {
					display: flex;
					flex-direction: row;
					align-items: center;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					flex: 1;

					.required {
						color: #f37364;
					}

					.size {
						color: #333333;
					}
				}

				.right_box {
					display: flex;
					flex-direction: row;
					align-items: center;

					.unit {
						margin-left: 8rpx;
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Medium;
						font-weight: 500;
						text-align: right;
						color: #000000;
					}

					.type {
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-right: 20rpx;

						.icont {
							width: 36rpx;
							height: 36rpx;
							margin-right: 8rpx;
						}

						.size {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: 500;
							text-align: right;
							color: #000000;
						}
					}
				}
			}
		}

		.addfoot {
			position: fixed;
			bottom: 0;
			width: 750rpx;
			height: 160rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(166, 179, 194, 0.30);
			display: flex;
			justify-content: center;
			padding-top: 10rpx;

			.addbtn {
				width: 710rpx;
				height: 88rpx;
				background: #73F0EA;
				border-radius: 16rpx;
				font-size: 34rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: center;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>